import java.util.Arrays;

public class Arr {
    public static int missingNumber(int[] nums) {
        if (nums.length == 0)
            return 0;
        Arrays.sort(nums);
        int ans = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != i) {
                ans = i;
                break;
            }
        }
        if (ans == -1) {
            return nums[nums.length - 1] + 1;
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] a = {1,2,3,4,5};
       // int ret = missingNumber();
        System.out.println(Arr.missingNumber(a));
    }
}
